#!/bin/ksh
#--------------------------------------------------------------
# Script Name : Start the Informatica,DAC,and BIEE 
# Created by  : hartlen
#         on  : 2009.10.15
# Updated by  : 
#         on  : 
# Parameters  : 
# Return Code : 0   = Normal End
# Comments    : 
#--------------------------------------------------------------
PATH=$PATH:/home/oracle/scripts ; export PATH
LOG=/tmp/stopapp.log
MSG_LOG=/oracle/newbackup/log/joblog_`date +%Y%m`.log ;export MSG_LOG
JOBNAME=Stop_APP          ; export JOBNAME

RC_CHK()
{
RC=$1
NAME=$2
if [[ $RC != 0 ]]
  then
      MSG_JOB E "Stop $NAME Failure"
      #exit 1
  else
      MSG_JOB I "Stopping $NAME"
fi
}

MSG_JOB S 
#------------------------
# stop Informatica
#------------------------
#export LANG=C
/oracle/app/Informatica/PowerCenter8.1.1/server/tomcat/bin/infaservice.sh shutdown >$LOG 2>&1
RC=$?; RC_CHK $RC "Informatica"
sleep 180

#------------------------
#Stop BIEE
#------------------------
/oracle/app/OracleBI/setup/run-sa.sh stop >>$LOG 2>&1 
RC=$?; RC_CHK $RC "BIEESA"
sleep 180
/oracle/app/OracleBI/setup/run-saw.sh stop >>$LOG 2>&1
RC=$?; RC_CHK $RC "BIEESAW"
sleep 180 

#------------------------
#Stop DAC
#------------------------
cd /oracle/app/DAC
nohup ./stopserver.sh >>$LOG 2>&1 &
RC=$?; RC_CHK $RC "DAC"
sleep 180

#-----------------------
#Stop Oc4j
#----------------------
U_NM=`whoami`
K_WD='oc4j'

CNT=`ps -ef|grep $U_NM|grep $K_WD|grep -v grep|wc -l`

if (( CNT != 0 ))
then
  until (( CNT == 0 ))
  do
    S_PID=`ps -ef|grep $U_NM|grep $K_WD|grep -v grep|awk '{print $2}'`
    kill -9 $S_PID
    sleep 10
    MSG_JOB I "$K_WD Process Killed"
    CNT=`ps -ef|grep $U_NM|grep $K_WD|grep -v grep|wc -l`
  done
  MSG_JOB I "$K_WD Process End"
else
  MSG_JOB I "OC4j Not Start"
fi

MSG_JOB N
